window._MiPlayer = {},
_MiPlayer = {
    version: "1.0",
    init: function(e, o) {
      console.log('video',e,o)
        var t = this;
        this.$player = e,
        this.event = o,
        this.$gui = $(this.event.jPlayer.options.cssSelectorAncestor).find(".jp-gui"),
        this.$controller = $(this.event.jPlayer.options.cssSelectorAncestor).find(".jp-interface"),
        this.$progress = this.$controller.find(".jp-progress"),
        this.$progressPlay = this.$controller.find(".jp-play-bar"),
        this.$progressPoint = this.$controller.find(".jp-progress-point"),
        this.$mute = this.$controller.find(".jp-mute"),
        this.$volumeBar = this.$controller.find(".jp-volume-bar"),
        this.$volumeBarValue = this.$controller.find(".jp-volume-bar-value"),
        this.$volumePoint = this.$controller.find(".jp-volume-point"),
        this.$playBtn = $(this.event.jPlayer.options.cssSelector.videoPlay),
        this.currentTime = this.event.jPlayer.status.currentTime,
        this.$loading = this.$gui.find(".jp-video-loading"),
        this.hideControllerSpeed = 3e3,
        this.progressDraging = !1,
        this.muted = !1,
        this.event.jPlayer.flash.used || window.ltIE9 || t.dragProgress(),
        this.showController(),
        this.$playBtn.show(),
        this.updateVolume(this.event.jPlayer.options.volume),
        window.ltIE9 || this.dragVolume(),
        this.checkFullscreen(),
        this.$mute.on("click", function() {
            t.muted ? t.volumeChange(.5) : t.volumeChange(0)
        })
    },
    play: function() {
        this.$playBtn.hide(),
        this.hideController(),
        this.event.jPlayer.flash.used || this.$progressPoint.show()
    },
    pause: function() {
        this.progressDraging || (this.$playBtn.show(),
        this.$loading.hide()),
        this.showController()
    },
    ended: function() {
        this.$playBtn.show(),
        this.$progressPoint.hide().css({
            left: 0
        }),
        this.showController()
    },
    hideController: function() {
        var e = this;
        e.hideControllerTimer && clearTimeout(e.hideControllerTimer),
        e.hideControllerTimer = setTimeout(function() {
            e.$controller.addClass("jp-controller-hide")
        }, e.hideControllerSpeed),
        e.$player.off(".toggleController").on("mousemove.toggleController", function() {
            e.showController()
        }).on("mouseleave.toggleController", function() {
            e.hideController()
        }),
        e.$controller.off(".toggleController").on("mousemove.toggleController", function() {
            e.showController()
        }).on("mouseleave.toggleController", function() {
            e.hideController()
        })
    },
    showController: function() {
        var e = this;
        e.hideControllerTimer && clearTimeout(e.hideControllerTimer),
        e.$controller.removeClass("jp-controller-hide")
    },
    dragProgress: function() {
        var e = this
          , o = e.$progress.width()
          , t = e.$progressPlay.width()
          , n = e.event.jPlayer.status.duration
          , i = 0
          , r = 0
          , l = 0;
        $(document).off(".jplayerpp").on("mousedown.jplayerpp", ".jp-progress-point", function(o) {
            e.progressDraging || (e.progressDraging = !0,
            i = $(this).offset().left,
            t = e.$progressPlay.width(),
            e.$player.jPlayer("pause", e.currentTime))
        }).on("mousemove.jplayerpp", function(n) {
            e.progressDraging && (r = n.pageX - i,
            l = (t + r) / o,
            e.updateProgress(t + r))
        }).on("mouseup.jplayerpp", function(o) {
            e.progressDraging && (e.progressDraging = !1,
            e.$player.jPlayer("play", l * n))
        })
    },
    updateProgress: function(e) {
        var o = this.$progress.width()
          , t = this.$progressPoint.width()
          , n = this.$progressPlay.width()
          , i = e ? e : n;
        n <= t / 2 ? i = 0 : n >= o - t && (i = o - t),
        this.$progressPoint.css({
            left: i / o * 100 + "%"
        }),
        e && this.$progressPlay.css({
            width: i / o * 100 + "%"
        })
    },
    volumeChange: function(e) {
        var o = Math.floor(10 * e);
        o < 1 ? (this.$player.jPlayer("mute", !0),
        this.muted = !0) : (this.$player.jPlayer("mute", !1),
        this.muted = !1),
        o < 5 ? this.$mute.addClass("jp-volume-small") : this.$mute.removeClass("jp-volume-small"),
        this.updateVolume(e)
    },
    dragVolume: function() {
        var e = this
          , o = e.$volumeBar.width()
          , t = e.$volumeBarValue.width()
          , n = this.$volumePoint.width()
          , i = (e.event.jPlayer.options.volume,
        0)
          , r = 0
          , l = 0
          , s = !1;
        $(document).off(".jplayervp").on("mousedown.jplayervp", ".jp-volume-point", function(o) {
            s || (s = !0,
            i = $(this).offset().left,
            t = e.$volumeBarValue.width())
        }).on("mousemove.jplayervp", function(u) {
            s && (r = u.pageX - i,
            l = (t + r - n / 2) / o,
            l >= 0 && l <= 1 && e.volumeChange(l))
        }).on("mouseup.jplayervp", function(e) {
            s && (s = !1)
        })
    },
    updateVolume: function(e) {
        var o = this.$volumeBar.width()
          , t = this.$volumePoint.width()
          , n = this.$volumeBarValue.width()
          , i = n * e
          , r = t / 2 / o;
        n <= t / 2 ? i = 0 : n >= o - t && (i = o - t),
        e > 1 || e < 0 || (this.$volumePoint.show().css({
            left: 100 * (e - r) + "%"
        }),
        this.$volumeBarValue.css({
            width: 100 * e + "%"
        }),
        this.$player.jPlayer("volume", e))
    },
    checkFullscreen: function() {
        if (this.inIframe && !this.supportFs) {
            document.domain = "mi.com";
            var e = !1;
            try {
                e = !!window.parent.document.domain
            } catch (o) {
                e = !1
            }
            e || this.$controller.find(".jp-toggles").hide()
        }
    },
    resize: function(e) {
        if (this.inIframe && !this.supportFs) {
            var o = $(window.parent.document).find("#miPlayerIframe");
            if (!o.length)
                return;
            e ? o.css({
                position: "fixed",
                top: 0,
                left: 0,
                width: "100%",
                height: "100%",
                "z-index": 9999
            }) : o.removeAttr("style")
        }
    },
    supportFullscreen: function() {
        var e, o, t, n = document, i = n.createElement("video"), r = {
            w3c: ["fullscreenEnabled", "fullscreenElement", "requestFullscreen", "exitFullscreen", "fullscreenchange", "fullscreenerror"],
            moz: ["mozFullScreenEnabled", "mozFullScreenElement", "mozRequestFullScreen", "mozCancelFullScreen", "mozfullscreenchange", "mozfullscreenerror"],
            webkit: ["", "webkitCurrentFullScreenElement", "webkitRequestFullScreen", "webkitCancelFullScreen", "webkitfullscreenchange", ""],
            webkitVideo: ["webkitSupportsFullscreen", "webkitDisplayingFullscreen", "webkitEnterFullscreen", "webkitExitFullscreen", "", ""],
            ms: ["", "msFullscreenElement", "msRequestFullscreen", "msExitFullscreen", "MSFullscreenChange", "MSFullscreenError"]
        }, l = ["w3c", "moz", "webkit", "webkitVideo", "ms"], s = !1;
        for (e = {
            support: {
                w3c: !!n[r.w3c[0]],
                moz: !!n[r.moz[0]],
                webkit: "function" == typeof n[r.webkit[3]],
                webkitVideo: "function" == typeof i[r.webkitVideo[2]],
                ms: "function" == typeof i[r.ms[2]]
            }
        },
        o = 0,
        t = l.length; o < t; o++) {
            var u = l[o];
            if (e.support[u]) {
                s = !0;
                break
            }
        }
        return s
    },
    setup: function(e) {
        var o = this
          , t = {
            title: "",
            vurl: "",
            vid: "",
            poster: "",
            width: 880,
            height: 536,
            solution: "html, flash",
            supplied: "m4v",
            auto: "0",
            onend: $.noop
        }
          , n = !1
          , i = $.extend(t, e);
        o.inIframe = function() {
            return self !== top
        }(),
        o.supportFs = o.supportFullscreen(),
        $("#J_miPlayerWrapper").css({
            width: i.width + "px",
            height: i.height + "px"
        }),
        i.vurl && $("#J_miPlayer").jPlayer({
            ready: function(e) {
                $(this).jPlayer("setMedia", {
                    title: i.title,
                    m4v: i.vurl,
                    poster: i.poster
                })
            },
            play: function(e) {
                0 !== e.jPlayer.status.currentTime || n || (o.init($(this), e),
                n = !0),
                o.play()
            },
            pause: function(e) {
                o.pause()
            },
            ended: function(e) {
                o.ended(),
                o.inIframe && "function" == typeof window.parent[i.onend] ? window.parent[i.onend]() : o.inIframe || "function" != typeof window[i.onend] || window[i.onend]()
            },
            click: function(e) {
                e.jPlayer.status.paused ? $(this).jPlayer("play") : $(this).jPlayer("pause")
            },
            timeupdate: function(e) {
                e.jPlayer.status.currentTime > 0 && o.updateProgress(),
                o.currentTime = e.jPlayer.status.currentTime
            },
            volumechange: function(e) {
                o.volumeChange(e.jPlayer.options.volume)
            },
            resize: function(e) {
                e.jPlayer.status.currentTime >= 0 && o.resize(e.jPlayer.options.fullScreen)
            },
            cssSelectorAncestor: "#J_miPlayerWrapper",
            swfPath: "jplayer",
            solution: i.solution,
            supplied: i.supplied,
            size: {
                width: i.width + "px",
                height: i.height + "px"
            },
            volume: .5,
            smoothPlayBar: !1,
            useStateClassSkin: !0,
            keyEnabled: !0,
            autohide: {
                hold: 3e3
            },
            noFullWindow: {
                msie: /msie [0-10]\./,
                ipad: /ipad.*?os [0-4]\./,
                iphone: /iphone/,
                ipod: /ipod/,
                android_pad: /android [0-3]\.(?!.*?mobile)/,
                android_phone: /android.*?mobile/,
                blackberry: /blackberry/,
                windows_ce: /windows ce/,
                iemobile: /iemobile/,
                webos: /webos/
            },
            waiting: function() {
                o.$loading.show()
            },
            playing: function() {
                o.$loading.hide()
            },
            seeking: function(e) {
                o.progressDraging || o.$progressPoint.hide()
            },
            seeked: function(e) {
                o.$progressPoint.show()
            },
            durationchange: function(e) {},
            canplay: function() {
                "1" === i.auto && $(this).jPlayer("play")
            },
            keyBindings: {
                play: {
                    key: 32,
                    fn: function(e) {
                        e.status.paused ? e.play() : e.pause()
                    }
                },
                volumeUp: {
                    key: 38,
                    fn: function(e) {
                        e.volume(e.options.volume + .1),
                        o.volumeChange(e.options.volume + .1),
                        e.flash.used || (o.showController(),
                        o.hideController())
                    }
                },
                volumeDown: {
                    key: 40,
                    fn: function(e) {
                        e.volume(e.options.volume - .1),
                        o.volumeChange(e.options.volume - .1),
                        e.flash.used || (o.showController(),
                        o.hideController())
                    }
                },
                fullScreen: {
                    key: 27,
                    fn: function(e) {
                        e.status.video && e.options.fullScreen && e._setOption("fullScreen", !e.options.fullScreen)
                    }
                }
            }
        })
    }
};